home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.c++
- Path: undergrad.math.uwaterloo.ca!sckettle
- From: sckettle@undergrad.math.uwaterloo.ca (Steve Kettle)
- Subject: Re: Is it OK to delete const *type pointers?
- Sender: news@undergrad.math.uwaterloo.ca (news spool owner)
- Message-ID: <DpAo8B.82s@undergrad.math.uwaterloo.ca>
- Date: Wed, 3 Apr 1996 16:24:10 GMT
- References: <4jhjub$fpc@mag1.magmacom.com>
- Nntp-Posting-Host: noether.math.uwaterloo.ca
- Organization: University of Waterloo
-
- In article <4jhjub$fpc@mag1.magmacom.com>,
- Acme Instant Dehydrated Boulder Kit <ezust@mag1.magmacom.com> wrote:
- >
- >Some compilers let me do this, others do not. What I would like to know is,
- >what does Stroustrup think? I.e. is it written somewhere in the ARM (I checked
- >but can't find it) or in the draft standard? If somoene could e-mail me a
- >quote or a pointer to a place where I can read where it says such a thing
- >should or should not be allowed, I would appreciate it!
- >
- >const int* array= new int[30];
- >delete[] array;
- >
- >MSVC says "can not delete const*"
- >Some versions of G++ also don't let me do this.
- >
-
- I don't think you should be allowed to delete a pointer to const memory.
-
- eg.
- main()
- {
- const int * temp;
- temp = new int;
- delete temp; // not allowed.
- }
-
- Think of the problems if you could delete the pointer. What if
- it pointed to read only memory - you delete and memory fault
- ( or soon to be memory fault ). When you have const int * temp
- basically this means the compiler will do every thing in its
- power to prevent you from modifying what temp points to, Unless
- you cast away the const or get at the memory some other way that
- is undetectable at compile time.
-
- --
-